//
//  DZReportBottomView.m
//  dzyc
//
//  Created by 蓝鳍互娱 on 2024/6/11.
//

#import "DZReportBottomView.h"
@interface DZReportBottomView()
@property (nonatomic,strong) UILabel *reportNumLab;
@property (nonatomic,copy) NSString *reportNum;
@end
@implementation DZReportBottomView
-(instancetype)init{
    if(self == [super init]){
        self.backgroundColor = DZHexA(@"#FFFFFF", 0.1);
        NSString *reportZhenJi = DZ_GETObject_UserDef(NSUserDefaults_ZhenJi);
        if(reportZhenJi.length > 0){
            self.reportNum = reportZhenJi;
        }else{
            self.reportNum = @"2.0";
        }
        [self makeSubView];
    }
    return self;
}
- (void)makeSubView{
    UILabel * reportAlertHeadLab = [[UILabel alloc] init];
    reportAlertHeadLab.font = [UIFont systemFontOfSize:DZRatio(32) weight:UIFontWeightBold];
    reportAlertHeadLab.textColor = DZHex(@"#43230A");
    reportAlertHeadLab.text = @"震级筛选";
    [self addSubview:reportAlertHeadLab];
    [reportAlertHeadLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(DZRatio(29)));
        make.top.equalTo(@(DZRatio(0)));
        make.bottom.equalTo(@(DZRatio(0)));
    }];
    UIButton * reportNumAddBtn = [[UIButton alloc] init];
    [reportNumAddBtn setTitle:@"+" forState:UIControlStateNormal];
    [reportNumAddBtn setTitleColor:DZHex(@"#222222") forState:UIControlStateNormal];
    [reportNumAddBtn addTarget:self action:@selector(reportNumAdd) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:reportNumAddBtn];
    [reportNumAddBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self);
        make.right.equalTo(@(-DZRatio(30)));
        make.width.equalTo(@(DZRatio(30)));
        make.height.equalTo(@(DZRatio(30)));
    }];
    self.reportNumLab = [[UILabel alloc] init];
    self.reportNumLab.font = [UIFont systemFontOfSize:DZRatio(32) weight:UIFontWeightBold];
    self.reportNumLab.textColor = DZHex(@"#B52519");
    self.reportNumLab.text = self.reportNum;
    self.reportNumLab.textAlignment = NSTextAlignmentCenter;
    [self addSubview:self.reportNumLab];
    [self.reportNumLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(reportNumAddBtn.mas_left);
        make.centerY.equalTo(reportNumAddBtn);
        make.width.equalTo(@(DZRatio(70)));
    }];
    UIButton * reportNumCutBtn = [[UIButton alloc] init];
    [reportNumCutBtn setTitle:@"-" forState:UIControlStateNormal];
    [reportNumCutBtn setTitleColor:DZHex(@"#222222") forState:UIControlStateNormal];
    [reportNumCutBtn addTarget:self action:@selector(reportNumCut) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:reportNumCutBtn];
    [reportNumCutBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self);
        make.right.equalTo(self.reportNumLab.mas_left);
        make.width.equalTo(@(DZRatio(30)));
        make.height.equalTo(@(DZRatio(30)));
    }];
}
- (void)reportNumCut{
    self.reportNum = [NSString stringWithFormat:@"%.02f",[self.reportNum floatValue] -0.1];
    if([self.reportNum intValue] < 1){
        self.reportNum = @"1.0";
        self.reportNumLab.text = self.reportNum;
    }
    DZ_SETObject_UserDef(NSUserDefaults_ZhenJi, self.reportNum);
}
- (void)reportNumAdd{
    self.reportNum = [NSString stringWithFormat:@"%.1f",[self.reportNum floatValue] +0.1];
    self.reportNumLab.text = self.reportNum;
    DZ_SETObject_UserDef(NSUserDefaults_ZhenJi, self.reportNum);
}
@end
